DC motor controlled by push button using Arduino & Tranceiver - Wireless...
Circuit Diagram:
Required Components:
Arduino uno/nano - 2 Nos
Battery - 2 Nos
Transceiver - 2 Nos
DC Motor - 2 Nos
L293D Motor Driver - 1 Nos
Push button - 4 Nos
10k Resister - 1 Nos
Program Code:
Transmitter Code:
#include <SPI.h>
#include "RF24.h"
byte data[1];
const uint64_t Pipe = 0xF0F0F0F0A1LL;
RF24 radio(9,10); // CE,CSN:
void setup() {
pinMode (4,INPUT_PULLUP);
pinMode (5,INPUT_PULLUP);
pinMode (6,INPUT_PULLUP);
pinMode (7,INPUT_PULLUP);
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(Pipe);
}
void loop() {
if(digitalRead(4)==HIGH||digitalRead(5)==HIGH||digitalRead(6)==HIGH||digitalRead(7)==HIGH){
data[0]=0;
}
if(digitalRead(4)==LOW){
data[0]=1;
}
if(digitalRead(5)==LOW){
data[0]=2;
}
if(digitalRead(6)==LOW){
data[0]=3;
}
if(digitalRead(7)==LOW){
data[0]=4;
}
radio.write(data,1);
Serial.println(data[0]);
}
Receiver Code:
#include <SPI.h>
#include "RF24.h"
byte data[1];
const uint64_t Pipe = 0xF0F0F0F0A1LL;
RF24 radio(9,10); // CE,CSN:
boolean var;
void setup() {
pinMode (4,OUTPUT);
pinMode (5,OUTPUT);
pinMode (6,OUTPUT);
pinMode (7,OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,Pipe);
radio.startListening();
}
void loop() {
if(radio.available()){
var=false;
while(!var){
var=radio.read(data,1);
if(data[0]==0){
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if(data[0]==1){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
}
if(data[0]==2){
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
}
if(data[0]==3){
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
if(data[0]==4){
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
}
}
Serial.println(data[0]);
}
Video:
Comments
Post a Comment