0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5Stack Core2: 照度センサーを使う

0
Last updated at Posted at 2021-09-01

M5Stack Core2 で Grove の照度センサーを使う方法です。
Port B に Grove を挿して、AD 変換を行います。12bit で変換されるので、0 から 4095 の整数になります。

IMG_20210901_143820.jpg

Port B に挿します。
IMG_20210901_143834.jpg

light_monitor/light_mnitor.ino
// ---------------------------------------------------------------
/*
	light_monitor.ino

						Feb/23/2026
*/
// ---------------------------------------------------------------
# include <M5Unified.h>
# define LIGHT 36

int icount = 0;
// ---------------------------------------------------------------
void setup() {
	auto cfg = M5.config();
	M5.begin(cfg);
	pinMode(LIGHT, INPUT); 

	M5.Lcd.setTextSize(3);
	M5.Lcd.println("Light Monitor");
	delay(1000);
	// while (!Serial) ;
	M5.Lcd.setBrightness(80);
	pinMode(LIGHT, INPUT);

	delay(1000);
}

// ---------------------------------------------------------------
void loop()
{
	M5.update();
	int value = analogRead(LIGHT);
	M5.Lcd.setCursor(5,60);
	Serial.println("value = " + String(value));
	M5.Lcd.println("value = " + String(value) + "   ");	
	M5.Lcd.println("icount = " + String(icount));
	delay(2000);

	icount++;
}

// ---------------------------------------------------------------

Arduino IDE 2.3.7 を使いました。

image.png

Grove 水分センサーも、インターフェースがアナログ電圧なので、同じプログラムが使えます。
IMG_20210901_145119.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?