Go Down

Topic: polar bear cup holder(hurry, please help) (Read 1 time) previous topic - next topic

angusyu

hey everyone,

I actually know a few about the programming on the arduino but i'm in hurry to set the circuits and codes for my installation, may anyone who knows programing  Arduino to rotate servo motor at certain temperature can give me a hand, thanks a lot!!

This is my situation,
I would like to do a design about a polar bear cup-holder, the temperature that the cup containing hot/cold water may affect the action of the polar bear by weaving its hand.
The temperature sensor i gonna use is LM35, the servo motor is SG90
I would like to use the angels 0'c, 90'c and 180'c to represent the three action of the polar bear, waving the right hand,  stay hands straight(not moving two side) and waving left hand respectively.

Cold water(temperature c<15)=waving the right hand, Room temperature(temperature 20<c<30)=stay hands straight, Hot water(temperature c>40)=waving left hand.

Also,
I would like to add a photo-resistor(CDS) on the cup holder installation

when the cup have blocked the resistor, the led light strips(5 volts) may turn on;
when nothing above the resistor, the led light strips(5 volts) may turn off

p.s. The two action above(waving hands+Led light on) is happening at the same time

May someone who know about arduino can help me with the programme and the circuit , this is my final project in this semester and I am really in hurry, thank you so much!!!! :)
 

pert

To start, write a test sketch for each component of your project and get each one working properly before combining everything.

Here are your components and suggested test sketches:
Arduino
File > Examples > 01.Basics > Blink
Write a sketch that prints "Hello World" to the serial monitor.

LM35
Write a sketch that prints the temperature reading to the serial monitor

servo
File > Examples > Servo > Sweep

LED light strip
Write a sketch that blinks the strip on and off

CDS
Write a sketch that prints the reading of the photoresistor to the serial monitor.

Doing multiple things at the same time:
File > Examples > 02.Digital > BlinkWithoutDelay

Once you have all the parts working and understand the code to control them it will be much easier to start putting your final project together and understand the cause of any problems you might encounter.

angusyu

thanks so much for the guide
Here is my code draft on the polar bear installation
can someone give me a hand checking whether the program work well or is there anyway to smooth the programme, thanks a lot


/* Sweep
  by BARRAGAN <http://barraganstudio.com>
  This example code is in the public domain.

  modified 8 Nov 2013
  by Scott Fitzgerald
  http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
float tempC;
int tempPin = 0;
int redPin= 3;
int greenPin= 5;
int bluePin= 6;
int red2Pin= 10;
int green2Pin= 8;
int blue2Pin= 9;

int blueTemp= 0; int greenTemp= 0; int redTemp= 0;
void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);
  pinMode(9, OUTPUT);
}

void loop()
{
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.println((byte)tempC);             //send the data to the computer

if(tempC<0){
  for (pos = 90; 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(5);                       // waits 15ms for the servo to reach the position
    }
}

if(tempC<12){
for (pos = 90; pos <= 90; 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(5);                       // waits 15ms for the servo to reach the position
    }
}

if(tempC<24){
  for (pos = 90; 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(5);                       // waits 15ms for the servo to reach the position
    }
}

if (analogRead(0) <= 100)
{
  pinMode(9, HIGH);
}

}

pert

pinMode(9, HIGH);
I think you mean
Code: [Select]
  digitalWrite(9, HIGH);

Please use code tags(</> button) when posting code or error/warning messages. I recommend always doing Tools > Auto Format on your sketch because this will make it easier for you to spot bugs and make it easier for us to read.

angusyu

how about this

float tempC;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position
int tempPin = 0;
int pResistor = 1; // Photoresistor at Arduino analog pin A0
int RPin=6;
int GPin=7;
int BPin=8;
int value;

void setup(){
myservo.attach(9);
pinMode(RPin, OUTPUT);
pinMode(GPin, OUTPUT);
pinMode(BPin, OUTPUT);// Set lepPin - 9 pin as an output
pinMode(pResistor, INPUT);// Set pResistor - A0 pin as an input (optional)

Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop() {
  Serial.println(analogRead(pResistor));
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.println((byte)tempC);             //send the data to the computer
int value = analogRead(pResistor);

  if (value == 0){
    digitalWrite(RPin, LOW);
    digitalWrite(GPin, LOW);
    digitalWrite(BPin, LOW);//Turn led off
  }
  else{
    digitalWrite(RPin, HIGH);
    digitalWrite(GPin, HIGH);
    digitalWrite(BPin, HIGH);//Turn led on
  }

  delay(500); //Small delay


    if(tempC<20){
    for (pos = 75; pos <= 82.5; 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
    }

    if(tempC>50){
    for (pos = 97.5; pos >= 105; 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
    }

    if(tempC>30&&tempC<51){
    for (pos = 90; pos >= 97.5; 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
    }

      if(tempC>19&&tempC<31){
    for (pos = 82.5; pos >= 90; 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
    }



 
delay(200);                           //wait 200 ms before sending new data
}

pert

Please use code tags(</> button) when posting code or error/warning messages. I recommend always doing Tools > Auto Format on your sketch because this will make it easier for you to spot bugs and make it easier for us to read.
Please edit your last post to follow the rules of the forum. At the top of each forum is this post:
How to use this forum - please read. Clearly you haven't read it or bothered to follow my suggestion. This shows a lack of respect for this forum. Why should we make an effort to help you if you can't be bothered to read and follow the rules?

Go Up