Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Programming Questions / HMC6352 compass converting degrees to direction problem? on: February 01, 2013, 02:23:45 pm
hello everyone
i want to covert to the value of the degree to direction
Code:
//All this does is read the heading from HMC6352 and spit it out via serial

#include <Wire.h>
int HMC6352SlaveAddress = 0x42;
int HMC6352ReadAddress = 0x41; //"A" in hex, A command is:

int headingValue;

void setup(){
  // "The Wire library uses 7 bit addresses throughout.
  //If you have a datasheet or sample code that uses 8 bit address,
  //you'll want to drop the low bit (i.e. shift the value one bit to the right),
  //yielding an address between 0 and 127."
  HMC6352SlaveAddress = HMC6352SlaveAddress >> 1; // I know 0x42 is less than 127, but this is still required

  Serial.begin(9600);
  Wire.begin();
}

void loop(){
  //"Get Data. Compensate and Calculate New Heading"
  Wire.beginTransmission(HMC6352SlaveAddress);
  Wire.write(HMC6352ReadAddress);              // The "Get Data" command
  Wire.endTransmission();

  //time delays required by HMC6352 upon receipt of the command
  //Get Data. Compensate and Calculate New Heading : 6ms
  delay(6);

  Wire.requestFrom(HMC6352SlaveAddress, 2); //get the two data bytes, MSB and LSB

  //"The heading output data will be the value in tenths of degrees
  //from zero to 3599 and provided in binary format over the two bytes."
  byte MSB = Wire.read();
  byte LSB = Wire.read();

  int headingSum = (MSB << 8) + LSB; //(MSB / LSB sum)
  headingSum = headingSum / 10;
int value = headingSum ;
Serial.print(headingSum);

  if (value > 68 || value < 112) {
    Serial.println("E");
  }
   

  delay(500);
}
but the result are wrong  the if statement doesn't work
any one can help me?
thanks for replaying
17  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: January 24, 2013, 12:42:18 pm
i try again but it still give's wrong value while i did the wire connection better?
Please anyone help me!
18  Using Arduino / Installation & Troubleshooting / Re: Arduino uno I/O pins output are 4.2v not 5v on: January 19, 2013, 11:58:59 pm
i make one pin output and take out by a jumper wire then measure it by mutlimeter.
i connect them relay and they can't swith the relay but when i connect directly the relay to 5+ it switch.
before i did this and there was no problem//
19  Using Arduino / Installation & Troubleshooting / Re: Arduino uno I/O pins output are 4.2v not 5v on: January 19, 2013, 11:41:51 pm
yes, all pins have the same problem and here the sketch:
Code:
int pin1= 11;
int pin2= 12;
int pin3= 13;
int counter = 0;
void setup(){
 Serial.begin(9600);
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT); 
  pinMode(pin3, OUTPUT);
 
}
 void loop() {
   int input = Serial.read();
   
   if (input == '3') {
      if (counter == 0) {
      Serial.print("on");
    analogWrite(pin3, 255);
     delay(5000);
      counter++;
      input = 0;
      }
   }
    if (input == '4') {
      if (counter == 0) {
     digitalWrite(pin3, LOW);
     Serial.print("low");
     counter++;
     input = 0;
      }
   }
    if (input == '1') {
       if (counter == 0) {
      Serial.print("1");
     digitalWrite(pin1, HIGH);
     
     delay(150);
      digitalWrite(pin1, LOW);
       counter++;
       input = 0;
       }
   }
    if (input == '2') {
       if (counter == 0) {
      Serial.print("2");
     digitalWrite(pin2, HIGH);
     delay(50);
      digitalWrite(pin2, LOW);
      delay(50);
      digitalWrite(pin2, HIGH);
     delay(50);
      digitalWrite(pin2, LOW);
       counter++;
       input = 0;
       
       }
       
   }
   counter = 0;
   }
   
20  Using Arduino / Installation & Troubleshooting / Arduino uno I/O pins output are 4.2v not 5v on: January 19, 2013, 05:52:54 pm
hi there
i have a problem with arduino when i checked output of digital pin it gave me 4.2v instead of 5v, and i need 5v,any solution?
i don't know what is wrong, thanks for helping!
best regards
21  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 23, 2012, 10:13:36 am
thanks for all replay but i have a question about the range
does anyone know more about this sensor technically??
22  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 01:55:13 pm
i just connected by jumber wire and breadboard
23  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 12:41:40 pm
what should i do to make it better?
24  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 12:30:55 pm
ah sorry here
https://www.sparkfun.com/products/10904

but the red rgb is 255,0,0
like if you put a red paper will it also be 255,0,0 or different because i think the light also effect it
thanks for helping me bro
25  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 12:09:02 pm
can your give me the sketch?
26  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 11:14:15 am
yellow paper
Code:
Red: 210 Green: 392 Blue: 136
Red: 180 Green: 336 Blue: 119
Red: 190 Green: 350 Blue: 119
Red: 180 Green: 336 Blue: 119


red paper
Code:
Red: 100 Green: 140 Blue: 731
Red: 100 Green: 140 Blue: 612
Red: 100 Green: 140 Blue: 476
Red: 100 Green: 140 Blue: 357
Red: 100 Green: 154 Blue: 306
Red: 100 Green: 154 Blue: 238
Red: 100 Green: 140 Blue: 170
27  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 10:56:43 am
does it need to be in a dark room or the room light doesn't affect it?
does it need to switch on the led on the board, or not?
please explain more clearly cuz i'm a newbie
28  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 10:19:09 am
could give an anther code example and can you give sketch if you can
with my best regards
29  Using Arduino / Sensors / Re: HDJD-S822 Color Sensor Code? on: December 22, 2012, 10:02:28 am
thanks for replaying, i just test some sticker papers , 5 cm away from the sensor
30  Using Arduino / Sensors / HDJD-S822 Color Sensor Code? on: December 22, 2012, 09:28:23 am
Hello everyone
i bought a HDJD-S822 Color Sensor from sparkfun. I search the hole internet but i found just one code for it
Code:
/*
An Arduino code example for interfacing with the
HDJD-S822-QR999 Color Sensor.  Put an object in front of the
sensor and look at the serial monitor to see the values the sensor
is reading.  Scaling factors and gains may have to be adjusted
for your application.

by: Jordan McConnell
 SparkFun Electronics
 created on: 1/24/12
 license: OSHW 1.0, http://freedomdefined.org/OSHW
 
Connect the gain pins of the sensor to digital pins 7 - 12 (or ground).
Connect the led pin to digital 13.
Connect Vr to analog 0, Vg to analog 1, and Vb to analog 2.
*/

// Define pins
const int ledpin = 13;
const int GSR1 = 12;
const int GSR0 = 11;
const int GSG1 = 10;
const int GSG0 = 9;
const int GSB1 = 8;
const int GSB0 = 7;

int redpin = A0;
int greenpin = A1;
int bluepin = A2;

// Sensor read values
int red = 0;
int green = 0;
int blue = 0;

void setup()
{
  Serial.begin(9600);

  pinMode(ledpin, OUTPUT);
  pinMode(GSR1, OUTPUT);
  pinMode(GSR0, OUTPUT);
  pinMode(GSG1, OUTPUT);
  pinMode(GSG0, OUTPUT);
  pinMode(GSB1, OUTPUT);
  pinMode(GSB0, OUTPUT);

  // Turn on the LED
  digitalWrite(ledpin, HIGH);
 
  // Set the gain of each sensor
  digitalWrite(GSR1, LOW);
  digitalWrite(GSR0, LOW);
  digitalWrite(GSG1, LOW);
  digitalWrite(GSG0, LOW);
  digitalWrite(GSB1, LOW);
  digitalWrite(GSB0, LOW);
}

void loop()
{
 
  // Read sensors
  // On page 7 of the datasheet, there is a graph of the
  // spectral responsivity of the chip.  Scaling factors were
  // selected based on this graph so that the gain of each
  // color is closer to being equal
  red = analogRead(redpin) * 10;
  green = analogRead(greenpin) * 14;
  blue = analogRead(bluepin) * 17;

  // Print values to the serial monitor
  Serial.print("Red: ");
  Serial.print(red, DEC);
  Serial.print("\t\tGreen: ");
  Serial.print(green, DEC);
  Serial.print("\tBlue: ");
  Serial.println(blue, DEC);

  delay(200);
}

i connected the pins as it says then i get this result now i don't know what to do with these?
Code:
Red: 20 Green: 350 Blue: 153
Red: 20 Green: 364 Blue: 153
Red: 10 Green: 280 Blue: 119
Red: 0 Green: 336 Blue: 221
Red: 0 Green: 336 Blue: 221
Red: 160 Green: 336 Blue: 204
Red: 160 Green: 336 Blue: 204
Red: 150 Green: 294 Blue: 170
Red: 170 Green: 336 Blue: 204
Red: 160 Green: 308 Blue: 187
Red: 180 Green: 378 Blue: 255
Red: 170 Green: 336 Blue: 204
Red: 170 Green: 336 Blue: 221
Red: 170 Green: 336 Blue: 204
Red: 180 Green: 364 Blue: 238
Red: 170 Green: 336 Blue: 204
Red: 180 Green: 378 Blue: 238
Red: 170 Green: 336 Blue: 204
Red: 180 Green: 37
i want to make something like when it detect red write in serial monitor red, same for other colors?
Please help me and i will be thanks full
thanks for replaying
Pages: 1 [2] 3 4 ... 6