How can i get the data from proximity sensor and send it to led?

Hello guys. Im new here and i stucked at a point of my project. I need to get a proximity data from this compilation. I mean it must be happen after 3 secs or 2 secs. the sensor will send the data compilation to COM point. After 3 secs the last proximity data will be sent by arduino to led as a brightness. How can i do it? :confused:

You forgot to show us your code, or tell us anything we need to know.

TheMemberFormerlyKnownAsAWOL:
You forgot to show us your code, or tell us anything we need to know.

#include <Wire.h>
#include <SparkFun_APDS9960.h>

#define APDS9960_INT 2
#define leds 10
#define PROX_INT_HIGH 10
#define PROX_INT_LOW 0

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint8_t proximity_data = 0;
int isr_flag = 0;
int i = 0;

void setup() {

// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println(F("------------------------------------"));
Serial.println(F(“SparkFun APDS-9960 - ProximitySensor”));
Serial.println(F("------------------------------------"));

attachInterrupt(0, interruptRoutine, FALLING);

// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F(“APDS-9960 initialization complete”));
} else {
Serial.println(F(“Something went wrong during APDS-9960 init!”));
}

// Adjust the Proximity sensor gain
if ( !apds.setProximityGain(PGAIN_2X) ) {
Serial.println(F(“Something went wrong trying to set PGAIN”));
}

if ( !apds.setProximityIntLowThreshold(PROX_INT_LOW) ) {
Serial.println(F(“Error writing low threshold”));
}
if ( !apds.setProximityIntHighThreshold(PROX_INT_HIGH) ) {
Serial.println(F(“Error writing high threshold”));
}

// Start running the APDS-9960 proximity sensor (no interrupts)
if ( apds.enableProximitySensor(true) ) {
Serial.println(F(“Proximity sensor is now running”));
} else {
Serial.println(F(“Something went wrong during sensor init!”));
}
}

void loop() {

// Read the proximity value
if ( !apds.readProximity(proximity_data) ) {
Serial.println(“Error reading proximity value”);
} else {
Serial.print("Proximity: ");
Serial.println(proximity_data);
if(proximity_data<10){
analogWrite(leds,i);
}
else{
analogWrite(leds,proximity_data);
}
}
delay(5);
}

void interruptRoutine() {
isr_flag = 1;
}

sorry about forgetting ^^

And im trying to do something like this but i couldnt find the codes of this project and im trying to write my own codes by combining other example’s codes.

analogWrite(leds,i);

i seems to be zero.

TheMemberFormerlyKnownAsAWOL: analogWrite(leds,i);

i seems to be zero.

yeah it's zero :D. Only I assign it with a variable

but that code works well. This isn't a problem. if u can watch the video u will understand what i mean about my problem. When the hand is stable on the sensor the light's brightness stuck at the own proximity level but i dont know how to code it .Also i couldnt find the code that is project at the video.

I don’t want to watch a video, I’m posting from my phone.
Why not explain what you want, with words?

https://github.com/mfalkvidd/DimmableKitchenLightGesture

That was the code for the video project I believe.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks… Tom… :slight_smile: