LOGIN
Shrey Fadia
7
Collaborator
Instrumentation Engineering student -- Hardware and coding Expert (Project Leader)
 · AhmedabadIndia
Share
Report
Get Link
TASK
In Progress
Reward › Contribution Review
Assigned to
Faiz Ur Rehman

Obstacle avoidance using Ultrasonic sensor

People Needed: 3-4

Estimated Time Commitment: 30 minutes

Tools Being Used: Google Hangouts, Collaborizm Discussion, Collaborizm Team Chat

Start Date: Aiming for Thursday at 11 EST. 5.4.17.

Reward: Collaborizm Resume Review written for each user participating

Users Participating: Shrey Fadia,

I need to have 2 ultrasonic sensors attached to the WheelChair. One on the front side of the chair and another just downside it at some angle. The other sensor is used to detect the slope or staircase so that the Wheelchair stops automatically once it detects it. The one ultrasonic sensor is already in use along with gesture mechanism. Let me know if anyone can do programming for multiple ultrasonic sensors in Arduino, which is 2 in our case.
This would be another milestone.
John Rodrigues Suraj Parasuram

Arduino
Robotics
Sensors
Arduino Uno
Arduino Mega
7 likes 
Like
Award Contribution
Load 19 previous comments
Shrey Fadia
7
Collaborator
Instrumentation Engineering student -- Hardware and coding Expert (Project Leader)
 · AhmedabadIndia
Share
Report
Get Link

Faiz Ur Rehman I want to make 2 ultrasonic sensors work simultaneously.

Like
0 like 
Award Contribution
Faiz Ur Rehman
6
Collaborator
Lets make this world a better place
 · MontrealCanada
Share
Report
Get Link

So what problem are you facing?

Like
0 like 
Award Contribution
North eugene
8
Top Contributor
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link

Timer 1 interrupts will make two sensors work very good , and they will neither clash nor make the program running slow , infet the entire program should be with timer1 interrupt and this is a kind of sequential exe , which mimics the multi tasking mode , which is not possible with one processor based system. but interupts divide the time between the multiple tasks and every function runs smooth
I will try Write the codes and post it

Applicant
Like
0 like 
Award Contribution
Faiz Ur Rehman
6
Collaborator
Lets make this world a better place
 · MontrealCanada
Share
Report
Get Link

yup North eugene is right interrupt is the best option for two sensors to work simultaneously, correction its not actually simultaneous because its not feasible, its like when either of sensors senses certain condition it will trigger an event.

Like
0 like 
Award Contribution
North eugene
8
Top Contributor
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link

https://playground.arduino.cc/Code/Timer1
has every thing to do with timer1 2 3 and the interrupt Plus other functions ,although the head will go circle while writing codes for things that are to be done
how ever am posting an example of sequential multi tasking , can run multiple servos and it has used a class
and no code redundancy , very nicely written . I have not written this code Just forwarding

#include <Servo.h> 

class Flasher
{
 // Class Member Variables
 // These are initialized at startup
 int ledPin;      // the number of the LED pin
 long OnTime;     // milliseconds of on-time
 long OffTime;    // milliseconds of off-time

 // These maintain the current state
 int ledState;                 // ledState used to set the LED
 unsigned long previousMillis;   // will store last time LED was updated

 // Constructor - creates a Flasher 
 // and initializes the member variables and state
 public:
 Flasher(int pin, long on, long off)
 {
 ledPin = pin;
 pinMode(ledPin, OUTPUT);     
   
 OnTime = on;
 OffTime = off;
 
 ledState = LOW; 
 previousMillis = 0;
 }

 void Update()
 {
   // check to see if it's time to change the state of the LED
   unsigned long currentMillis = millis();
    
   if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
   {
     ledState = LOW;  // Turn it off
     previousMillis = currentMillis;  // Remember the time
     digitalWrite(ledPin, ledState);  // Update the actual LED
   }
   else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
   {
     ledState = HIGH;  // turn it on
     previousMillis = currentMillis;   // Remember the time
     digitalWrite(ledPin, ledState);   // Update the actual LED
   }
 }
};

class Sweeper
{
 Servo servo;              // the servo
 int pos;              // current servo position 
 int increment;        // increment to move for each interval
 int  updateInterval;      // interval between updates
 unsigned long lastUpdate; // last update of position

public: 
 Sweeper(int interval)
 {
   updateInterval = interval;
   increment = 1;
 }
 
 void Attach(int pin)
 {
   servo.attach(pin);
 }
 
 void Detach()
 {
   servo.detach();
 }
 
 void Update()
 {
   if((millis() - lastUpdate) > updateInterval)  // time to update
   {
     lastUpdate = millis();
     pos += increment;
     servo.write(pos);
     Serial.println(pos);
     if ((pos >= 180) || (pos <= 0)) // end of sweep
     {
       // reverse direction
       increment = -increment;
     }
   }
 }
};


Flasher led1(6, 300,500);
Flasher led2(12, 500, 500);
Flasher led3(13, 1000, 1022);

Sweeper sweeper1(10);
Sweeper sweeper2(11);
Sweeper sweeper3(52);

void setup() 
{ 
 Serial.begin(9600);
 sweeper1.Attach(11);
//  sweeper2.Attach(10);
 sweeper3.Attach(52);
 
} 


void loop() 
{ 
// sweeper1.Update();
 sweeper2.Update();
 sweeper3.Update();
 led1.Update();
 led2.Update();
 led3.Update();
}
Applicant
Like
0 like 
Award Contribution
North eugene
8
Top Contributor
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link

Flasher led1(6, 300,500); pin 6
Flasher led2(12, 500, 500); pin 12
Flasher led3(13, 1000, 1022); pin 13

Sweeper sweeper1(10); pin 10
Sweeper sweeper2(11); pin 11
Sweeper sweeper3(52); pin 52 if Mega or Due

Applicant
Like
1 like 
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
New Post
Help
Start Project
Online Users
Share Link
Write something before you submit it!
Photo updated
Request Sent!
Updated
Copied to Clipboard