We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to make the clock in Processing stop at the exact time when people are in front of the distance sensor. When there is no one there, it will move fast and the hands will carry on spinning.
Can anyone help me do this?
Thanks
Answers
What code do you have so far? Have you explore the basic examples? There is a clock already implemented.
How fast is fast? Fast as in a thunder flash or as one second on Earth time?
Kf
I have the clock code. 5 secs from when the minute hand does a full 360. I need Processing to link with the Arduino and Infrared sensor. How would I do this?
Thanks Kf
You need to get the arduino working and it should be reading your infrared sensor. Does the infrared kit comes with any provided examples? What are the specs of your sensor and your arduino? How much have you done so far?
You can check previous post in the forum:
https://forum.processing.org/two/search?Search=infrared
https://forum.processing.org/two/search?Search=arduino
For the first one, you will get lots of kinetic code as well. Just focus in arduino posts. For the second search, you will have lots of arduino code to get you started.
Kf
No it does not. I have an Arduino UNO and an Infrared Sharp Sensor.
This is the code I have so far. It does not work.
include <Servo.h>
Servo myClock; // create servo object to control a servo int handPos = 0; // variable to store the servo position int distanceSensor = A0; // select the input pin for the potentiometer
void setup() { myClock.attach(8); // attaches the servo on pin 9 to the servo object }
void loop() { // read the value from the sensor: distanceSensor = analogRead(distanceSensor); if (distanceSensor < 200) { for (handPos = 0; handPos <= 60; handPos = handPos + 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myClock.write(handPos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (handPos = 180; handPos >= 0; handPos -= 1) { // goes from 180 degrees to 0 degrees myClock.write(handPos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position
void setup(){ Serial.begin(9600); }
void draw(){ int val = analogRead(sensorPin); Serial.println(val);
//just to slow down the output - remove if trying to catch an object passing by delay(300);
}
} }
Cheers thanks Kf
I'll check out the links.
Bservo
Please edit your post and format your code. Select your code and press ctrl+o and have an empty line above and below your code.
Kf
Cheers this is how it is.
If you want to have Processing control you're Arduino you will need to use Firmata on both Processing and Arduino. Here is a good reference to get you started:
https://adestefawp.wordpress.com/learning/using-arduino-firmata-and-processing-together/
Then you can post some of you're code if it doesn't work and we can help you.
@Bservo
So everything is done in your arduino side. You read the sensor using your arduino and then you drive the step motor. So I see what happens here. Line 14 is ea example of what >>not<< to do. the reason is because you are blocking the loop. Lines 25 to 36 are not needed. Instead try this below. Notice here you are interacting with the Arduino IDE and not the Processing IDE. Those lines from 25 to 36 are for a processing IDE, when you are trying to communicate to the arduino device via serial.
Kf
Cheers guys. I have changed my project so I won't be using Processing anymore.
I am now just using an arduino. Any chance you could still help me.
So I would like the distance sensor to stop the servo when a certain number is met e.g. 300. Is this possible?
Cheers
That is what the code above does. Did you try it?
Kf
@kfrajer has provided all the information that you need.
Unfortunately my coding skills are not up to scratch. This is what I tried below.
analogRead >300(distanceSensor); write(handPos) (0); `
I want my analogRead (Distance Sensor) to reach a high number. It will tell the Servo to stop, but when the number reduces to tell the Servo to start up again. Then repeat. I know this needs to go into Loop.
Thanks
Sorry, those are typos. I forgot to mention I didn't run the code.
Implement the following corrections:
handPos+=stepRot;
if(handPos>=360)
Kf
There is a typo at line 32 and handle was never declared, try this:
handPos += stepRot; if(handPos >= 360) handPos=0; //Reset position field after one single turn
Nice one guys. Cheers so I have started the code and it has come back with no errors. Thanks all.
The problem I have is that how do I connect the infrared sensor and the servo together onto the arduino as one.
You guys are a massive help seriously.
Thanks
Bservo
For your next step an Arduino proto shield would be a good place to start:
https://www.sparkfun.com/products/11665
I have breadboard would that not work?
Thanks
Sure it would work and if you don't want a permanent setup it might be better than a proto shield.
Yes thanks. I tried setting them up together but no avail. I think it may be due to the voltage that is not helping the arduino work.
I have put the Servo pins on the breadboard. Red on +2. Black on -1. Yellow on Digital 9 of the arduino.
I have put the infrared distance sensor on. Red on +28. Black on +25. White on A0 of the arduino.
Then I have +20 to 5V. Also, -21 to GND both of the arduino.
When the code is uploaded nothing. Thanks again
I think your questions could be answered better if you post some details and photos at the link below....good luck!!
https://forum.arduino.cc/index.php?board=3.0