Question

Write program and show the electric connection for an Arduino UNO. To control a two-channel relay...

Write program and show the electric connection for an Arduino UNO.

To control a two-channel relay module, the first channel will switch on a 5v stepper motor with ULN2003 driver board. When the stepper motor switches off directly the second channel will switch on that is connected to Infrared sensor (HC -SR501), when the sensor detects an infrared radiation it will send a signal to transmitter/receiver (RF 433 MHz). To show a sound output by speaker (ISD 1820).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//declare variables for the motor pins

int motorPin1 = 8; // Blue - 28BYJ48 pin 1

int motorPin2 = 9; // Pink - 28BYJ48 pin 2

int motorPin3 = 10; // Yellow - 28BYJ48 pin 3

int motorPin4 = 11; // Orange - 28BYJ48 pin 4

// Red - 28BYJ48 pin 5 (VCC)

int motorSpeed = 1200; // variable to set stepper speed

int count = 0; // count of steps made

int countsperrev = 512; // number of steps per full revolution

int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////

void setup() {

//declare the motor pins as outputs

pinMode(motorPin1, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(motorPin3, OUTPUT);

pinMode(motorPin4, OUTPUT);

Serial.begin(9600);

}

//////////////////////////////////////////////////////////////////////////////

void loop(){

if(count < countsperrev )

clockwise();

else if (count == countsperrev * 2)

count = 0;

else

anticlockwise();

count++;

}

//////////////////////////////////////////////////////////////////////////////

//set pins to ULN2003 high in sequence from 1 to 4

//delay "motorSpeed" between each pin setting (to determine speed)

void anticlockwise()

{

for(int i = 0; i < 8; i++)

{

setOutput(i);

delayMicroseconds(motorSpeed);

}

}

void clockwise()

{

for(int i = 7; i >= 0; i--)

{

setOutput(i);

delayMicroseconds(motorSpeed);

}

}

void setOutput(int out)

{

digitalWrite(motorPin1, bitRead(lookup[out], 0));

digitalWrite(motorPin2, bitRead(lookup[out], 1));

digitalWrite(motorPin3, bitRead(lookup[out], 2));

digitalWrite(motorPin4, bitRead(lookup[out], 3));

}

Add a comment
Know the answer?
Add Answer to:
Write program and show the electric connection for an Arduino UNO. To control a two-channel relay...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am a student of EST, and now I have a group open project, which required us to design a device ...

    I am a student of EST, and now I have a group open project, which required us to design a device using components as shown below. We can choose maximum 9 credits worth of components, and the credits are marked after each component. I am asking for some good ideas. Please describe what can be made and what components should be used. Please provide ideas as more as possible. 1-101-Ultrasonic Sensor-Credit 1 2-102-Sound Wave Sensor (MAX9812)- Credit 2 3-103-Microphone Sound...

  • I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED str...

    I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT