Task:
We’ll make a box of Plexiglas that is linked to an android app. In the app, you can create your own to-do lists. When you checked off the chores listed in the app, the box will open, by means of a lock. In the box, you have already put something you would like to have (a reward).
This can be used by e.g. families - the kids have to clean the room before Saturday to get the candy in the box. When the children checked in the boxes in the list the parents have to approve. Then the box will open and they will get their reward.
Technology we use:
-
An Arduino Uno
-
9v battery
-
HC06 bluetooth
-
Breadboard
-
Servo motor “Futaba S3003”
Problem:
-
The problem is that we want to connect to Bluetooth - the lamp on the bluetooth is flashing but we can’t get any communication between the bluetooth and the phone.
-
We have obtained the motor to spin, by means of the code bellow. Then we want to have a button for “open” and one for “close” in our android app. So we have got the motor to spin, but we want to control it with open and close buttons. What code shall we use?!
We believe we need to put any “if” or “else” code?!
Is there anyone here who is good at this and can help us?
Thanks in advance!
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}