Handmade LED and DC motor control with capacitive sensor

0
5233

Handmade LED and DC motor control with capacitive sensor

You made my handmade capacitive sensor with the number of LEDs and DC motor’s direction of rotation set up projects if they offer. our first project to know a little bit today.

Two the number of capacitive sensor LEDs, if you close the number of LEDs by sliding on without touching the sensor of your hand, reducing If you want to maintain control two if you press your hand to the capacitive sensor engine tab t the hands of the right sensor tab, right engine, the engine returns to the left side if you close the left sensor of your hand.

Used materials

  • Arduino UNO R3
  • Breadboard
  • Aluminium foil
  • Patch cable
  • Resistance (4 units of 220 ohms, 2 units of 140 kilohms)
  • 4 units LEDs
  • LCD display 16 × 2
  • DC Motors
  • Integrated with L293d
  • Potentiometer

Capacitive sensors are Made

capacitive sensor
capacitive sensor

Aluminium foil, as shown in the photos of 110mm x 110 mm in size cut cables are sticking to a hard surface  foil. We’re doing the same thing in the two sensors.

If you wish, you can change the size of the sensor, but may need to change the size of the resistor is connected to the sensor.

Circuit diagram 

capacitive sensorcapacitive sensorI did one circuit diagram 2 As you can see above, I draw  for the whole circuit would be too complicated to set up than a photo thought you halves

Resistors; LEDs connected to 220 ohms, and the resistance value of which is connected to the sensor 140kohm.

Arduino code

#include <CapacitiveSensor.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int LED4=A1 ;
const int LED1=A0 ;
const int LED2=7 ;
const int LED3=10 ;
const int motorpin1=A3 ;
const int motorpin2=A2 ;
int sayici ;
int first ;
CapacitiveSensor   cs_4_2 = CapacitiveSensor(6,9);
CapacitiveSensor   cs_4_3 = CapacitiveSensor(13,8);
void setup()
{
lcd.begin(16, 2);
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
Serial.begin(9600);
pinMode(motorpin1,OUTPUT);
pinMode(motorpin2,OUTPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
}
void loop()
{
long total1 =  cs_4_2.capacitiveSensor(100);
long total2 =  cs_4_3.capacitiveSensor(100);
delay(50) ;
lcd.setCursor(1,1) ;
lcd.print(sayici);
lcd.setCursor(5,1) ;
lcd.print(first);
Serial.println(total2);
Serial.println(total1);
Serial.println("\t");
if(   total1<40 && total2<40  )
first=0;
if( first==0 && total1>50 && total2<50 && sayici!=4  )
first=2;
if( first==0 &&  total1<50 && total2>50 && sayici!=0)
first=1;
if(first==2 && total1>50 && total2>50 && sayici<4 && sayici>=0 )
{
++sayici ;
first=3 ;
}
if(first==1 && total1>50 && total2>50 && sayici<=4 && sayici>0 )
{
--sayici ;
first=3;
}
if(total1>150 && total2>150 && first!=5 )
{
if(sayici==9)
{
sayici=0 ;
first=5;
analogWrite(motorpin1,0);
analogWrite(motorpin2,0);
}
else if(sayici!=9)
sayici=9 ;
first=5 ;
}
switch(sayici)
{
case 0 :
lcd.setCursor(0,0) ;
lcd.print("led sekmesi");
digitalWrite(LED2,LOW) ;
analogWrite(LED1,LOW) ;
digitalWrite(LED3,LOW) ;
analogWrite(LED4,LOW) ;
break;
case 1 :
digitalWrite(LED2,LOW) ;
analogWrite(LED1,255) ;
digitalWrite(LED3,LOW) ;
analogWrite(LED4,0) ;
break;
case 2 :
digitalWrite(LED2,HIGH) ;
analogWrite(LED1,255) ;
digitalWrite(LED3,LOW) ;
analogWrite(LED4,0) ;
break;
case 3 :
digitalWrite(LED2,HIGH) ;
analogWrite(LED1,255) ;
digitalWrite(LED3,HIGH) ;
analogWrite(LED4,0) ;
break;
case 4 :
digitalWrite(LED2,HIGH) ;
analogWrite(LED1,255) ;
digitalWrite(LED3,HIGH) ;
analogWrite(LED4,255) ;
break;
case 9 :
lcd.setCursor(0,0) ;
lcd.print("motor sekmesi");
if (total1>50 && total2<50)
{
analogWrite(motorpin1,300);
analogWrite(motorpin2,0);
}
if(total2>50 && total1<50)
{
analogWrite(motorpin1,0);
analogWrite(motorpin2,300);
}
else if(total2<50 && total1<50)
{
analogWrite(motorpin1,0);
analogWrite(motorpin2,0);
}
default:
break ;
}
}